//
// Created by Administrator on 2024/5/21.
//

#include <string>
#include <sstream>

#include "luabase.h"
#include "utils.h"

extern "C"
{
#include "lauxlib.h"
}

static int lua_clock(lua_State *L) {
    lua_pushnumber(L, clockX());
    return 1;
}

static int lua_sleep(lua_State *L) {
    auto s = lua_tonumber(L, 1);
    sleep(s);
    return 0;
}

static const luaL_Reg base_funcs[] = {
        {"clock", lua_clock},
        {"sleep", lua_sleep},
        {NULL, NULL}};

void luaopen_baseX(lua_State *L) {
    lua_pushglobaltable(L);
    luaL_setfuncs(L, base_funcs, 0);
}

void luaopen_baseX_sol(sol::state *lua) {
    lua->set_function("clock", clockX);
    lua->set_function("sleep", sleep);
}